<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$cid = $route->GET('cid');
if ($cid != ""){
	require_once "offices_list.php";
	die;
}

require_once ADMIN.DS."/head.php";
?>
<h1>Выбрать компанию</h1><br />
<input type="text" placeholder="Поиск..." id="search" />
<br /><br />
<table cellpadding='0' cellspacing='0' class='list' id="table">
	<tr class='table_header'>
		<td width='50px'>ID</td>
		<td width='300px'>Название</td>
		<td width='80px'>Офисов</td>
	</tr><?php
		$query = "select `C`.*,count(`O`.`ao_id`) as `offices`
			from `companies` as `C`
			left join `additional_office` as `O`
			on `C`.`company_id` = `O`.`company_id`
			where `C`.`city_id` = '".$current_admin_city['city_id']."'
			group by `C`.`company_id` order by `name`";
		$companies = $db->getTable($query);
		foreach ($companies as $company){
			echo "<tr class='tr'><td>$company[company_id]</td>";
			echo "<td class='find'><a href='/admin/offices?cid=$company[company_id]'>$company[name]</a></td>";
			echo "<td>$company[offices]</td>";
			echo "</tr>";
		}
?></table>

<?php require_once ADMIN.DS."/footer.php"; ?>